<template>
  <div :style=" backgroundValue ? 'background : ' + backgroundValue : ''">
    <el-config-provider :locale="zhCn">
      <router-view />
    </el-config-provider>
  </div>
</template>

<script lang="ts">
  import {
    defineComponent,
    computed,
    onMounted,
    ref,
    provide
  } from 'vue'
  import {
    useStore
  } from 'vuex'
  import {
    ElConfigProvider
  } from 'element-plus'
  import zhCn from 'element-plus/lib/locale/lang/zh-cn'
  import {
    getEnterpriseWebsiteConfig
  } from '@/api/common/common'
  import {
    useActions
  } from '@/store/utils/useActions'
  import {
    useRouter
  } from 'vue-router'
  export default defineComponent({
    name: 'App',
    components: {
      ElConfigProvider
    },
    setup() {
      const router = useRouter()
      const store = useStore()
      const showPlayView = computed(() => store.state.showPlayView)
      const showDialog = computed(() => store.state.showDialog)
      const backgroundValue = ref('')
      provide('backgroundValue', backgroundValue)
      const errorObj = ref({
        code: '',
        msg: ''
      })
      provide('errorObj', errorObj)
      const storeActions: any = useActions('enterpriseConfig', ['setEnterpriseConfig'])
      onMounted(() => {
        initWebsiteConfig()
      })

      const initWebsiteConfig = () => {
        getEnterpriseWebsiteConfig().then(response => {
          if (response && response.code && response.code === 900) {
            errorObj.value.code = response.code
            errorObj.value.msg = response.msg
            // 跳转到 内部错误页
            router.push({
              path: '/404'
            })
            return
          }
          backgroundValue.value = response.data.websiteDefaultColor
          storeActions.setEnterpriseConfig(response.data)
        })
      }

      return {
        zhCn,
        showPlayView,
        showDialog,
        backgroundValue,
        ...storeActions
      }
    }
  })
</script>
<style lang="scss">
  @import "./styles/index.scss";
  @import "./styles/common.scss";
  @import "./styles/btn.scss";
  @import "./styles/dynamic.scss";
</style>
